package cn.quang.search.admin.mapper;

import cn.quang.search.admin.entity.po.EntityTable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author:  Entity Generator
 * @since:  2024-02-28 10:57:07
 */
public interface EntityTableMapper extends BaseMapper<EntityTable> {
    @Select(
            " SELECT * FROM entity_table WHERE data_source_id = #{dataSourceId} "
    )
    List<EntityTable> selectByDataSourceId(@Param("dataSourceId") long dataSourceId);

    @Select(
            " SELECT * FROM entity_table WHERE data_source_id = #{dataSourceId} AND table_name = #{tableName} "
    )
    EntityTable selectByTableName(@Param("dataSourceId") long dataSourceId, @Param("tableName") String tableName);

    @Select(
            " <script> " +
                    "     SELECT * FROM entity_table " +
                    "     <where> " +
                    "       <if test='dataSourceIds != null and dataSourceIds.size() > 0'> " +
            "         <foreach collection='dataSourceIds' item='item' open='AND data_source_id IN (' close=')' separator=','> " +
            "           #{item} " +
            "         </foreach> " +
            "       </if> " +
            "     </where> " +
            " </script> "
    )
    List<EntityTable> selectByDataSourceIds(@Param("dataSourceIds") List<Long> dataSourceIds);
}
